import axios from 'axios';
import config from "@/util/config.js";

const API_URL = config.mdUrl+'/md/customer';

const customerAPI = {
    // 添加客户信息
    addCustomer(param, callback) {
        axios.request({
            url: `${API_URL}/add`,
            method: 'post',
            headers: {
                "Content-Type": "application/json;charset=UTF-8"
            },
            data: JSON.stringify(param)
        }).then((res) => {
            callback(res.data);
        })
    },

    //修改客户信息
    updateCustomer(param, callback) {
        axios.request({
            url: `${API_URL}/update`,
            method: 'put',
            headers: {
                "Content-Type": "application/json;charset=UTF-8"
            },
            data: JSON.stringify(param)
        }).then((res) => {
            callback(res.data);
        })
    },

    //删除客户信息
    deleteCustomer(param, callback) {
        axios.request({
            url: `${API_URL}/${param.id}/${param.status}`,
            method: 'delete',
        }).then((res) => {
            callback(res.data);
        })
    },
    //查询客户信息
    getCustomers(param, callback) {
        axios.request({
            url: `${API_URL}/query/${param.page}/${param.limit}?keyWord=${param.name}`,
            method: 'get'
        }).then((res) => {
            callback(res.data);
        })
    },
    //获取所有客户数量
    getCount(callback) {
        axios.request({
            url: `${API_URL}/count`,
            method: 'get',
        }).then((res) => {
            callback(res.data);
        })
    }

}
export default customerAPI;